/*******************************************************************\
*	file: 		AtpClose.c											*
*	version:	1.06§												*
* 																	*
* This command disassociates the node with the network.				*
*																	*
* -----------------------------------------------------------------	*
* By:	 Donald Koscheka, Greg Kimberly								*
* Date:	21-Sept-87													*
* ©	Copyright 1987, Apple Computer, Inc.							*
*	All Rights Reserved												*
*																	*
* -----------------------------------------------------------------	*
*						Modification History						*
* -----------------------------------------------------------------	*
*  Date	   	| By	|	 				Description					*
* -----------------------------------------------------------------	*
* 21-Sep-87	| GK	| file created									*
*  5-Nov-87	| DK	| added return result							*
* 11-Dec-87	| DK	| put disposHandle into atKill					*
* 14-Jan-88	| DK	| modified to reflect decoupling of atp and nbp	*
*			|		| (clears out global address container)			*
* -----------------------------------------------------------------	*
\*******************************************************************/

/*******************************************************************\
							Build Sequence
C -q2 -g -o "{hpo}"ATPClose.c.o "{atp}"ATPClose.c
	link  -sn Main=ATPClose -sn STDIO=ATPClose ¶
		 -sn INTENV=ATPClose -rt XCMD=300 ¶
		 -m ATPCLOSE ¶
		  "{hpo}"ATPClose.c.o "{hpo}"atalkxcmd.c.o "{hpo}"xcmdutils.c.o ¶
		 "{CLibraries}"CInterface.o ¶
		 "{Libraries}"Interface.o ¶
		 -o "{hp}"HyperAppleTalk

\*******************************************************************/

#include <Types.h>
#include <Memory.h>
#include <Resources.h>
#include <OSUtils.h>
#include <appleTalk.h>
#include <HyperXCmd.h>
#include <atalkXCMD.h>
#include <XCMDUtils.h>

pascal void ATPClose(paramPtr)
	XCmdBlockPtr	paramPtr;
/**********************************
* Close down access to the network 
* deallocating all memory used by
* the session.
*
* In:	nil
*
* Out: Error Result is returned to hypercard
**********************************/
{
	ATPBlock 	*atp;
	short		result = noErr;
	
	atp = (ATPBlock *)RetrieveHandle(paramPtr, GLOBALATPDATA);
	if( atp ){
		if( atp->checkPoint == RECEIVING )	/*** we're in a callback, so hold off	***/
			atp->checkPoint = CLOSE_NOW;	/*** on the close until callback is done***/
		else{								/*** if we're not in a callback, we can ***/	
			result = ATPKill( atp );		/*** close down immediately.			***/
			SaveHandle( paramPtr, GLOBALATPDATA, nil );
		}
	}
	paramPtr->returnValue = ErrorReturn( result );
}

